package com.kiss.fw.jsf.mb;

import java.util.Map;

import javax.faces.context.FacesContext;

import com.kiss.fw.dto.AbstractPageDTO;

public abstract class AbstractManagedBean {
	protected AbstractManagedBean() {
	}
	
	protected static Map<String, Object> getApplicationScope () {
		return getFacesContext().getExternalContext().getApplicationMap();
	}
	
	protected static FacesContext getFacesContext () {
		return FacesContext.getCurrentInstance();
	}
	
	protected static Map<String, String> getRequestParam () {
		return getFacesContext().getExternalContext().getRequestParameterMap();
	}
	
	protected static Map<String, Object> getRequestScope () {
		return getFacesContext().getExternalContext().getRequestMap();
	}
	
	protected static Map<String, Object> getSessionScope () {
		return getFacesContext().getExternalContext().getSessionMap();
	}
	
	protected static String getWindowTitle(final String _dtoKey) {
		AbstractPageDTO dto = (AbstractPageDTO)getRequestScope().get(_dtoKey);
		return dto == null ? "" : dto.getWindowTitle();
	}
	
	protected static String getPageTitle(final String _dtoKey) {
		AbstractPageDTO dto = (AbstractPageDTO)getRequestScope().get(_dtoKey);
		return dto == null ? "" : dto.getPageTitle();
	}
	
	protected boolean isUserInRole(final String _role) {
		return getFacesContext().getExternalContext().isUserInRole(_role);
	}
}